
//引入网络库
import { get, post } from "../../util/util.js"
// 获取全局应用程序实例对象
var app = getApp();

// 创建页面实例对象
Page({
  /**
   * 页面名称 
   */
  name: "moviedetial",
  /** 
   * 页面的初始数据
   */

  data: {
    uid: '',
    id: '',
    is_collect: '',
    shenqing: '申请',
    selectedLeft: true,
    selectedRight: false,
    gsggData: '',//故事梗概
    tbbzData: '',//特别备注
    jsrwData: {},//角色小传
    lxrData: {},//联系人信息
    shengao: '',
    tixing: '',
    yanzhi: '',
    techang: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },

  onLoad: function (o) {
    var that = this;
    console.log("上级列表传入数据" + o.Fid + '==uid=' + o.Uid)
    // var jbxx = {};
    //获取剧组详情
    post("/film/view", { fid: o.Fid, uid: o.Uid }).then(data => {
      var zmimg = data.data.status == 2 ? '/resources/zm_icon.png' : '/resources/wzm_icon.png';
      that.setData({
        id: o.Fid,
        uid: o.Uid,
        is_collect: data.data.is_collect,
        headimg: data.data.headimg,
        bgimg: data.data.bgimg,
        bootdate: data.data.boot_date,
        jzname: data.data.name,
        zmstatus: zmimg,
        ticai: data.data.subject_name,
        pingtai: data.data.play_platform_name,
        daoyan: data.data.director,
        zhizuoren: data.data.producer,
        fudaoyan: data.data.deputy_director,
        xuanjue: data.data.chief_chooser,//
        paishedi: data.data.shoot_place,
        paishezhouqi: data.data.shoot_days + "天",
        zmkaishi: data.data.begin_date,
        zmjieshu: data.data.end_date,
        gushi: data.data.story_desc,
        roles: data.data.roles,
        // lxdianhua: data.data.contact_mobile,
        // lxweixin: data.data.contact_wx,
        // lxyouxiang: data.data.contact_email,
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  selectedLeft: function (e) {
    this.setData({
      selectedRight: false,
      selectedLeft: true
    })
  },

  selectedRight: function (e) {
    this.setData({
      selectedLeft: false,
      selectedRight: true
    })
  },

  modalShare: function () {
    wx.showModal({
      title: '分享',
      content: '确定是否分享？',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  modalCollect: function () {
    var that = this;
    if (that.data.is_collect == 0) {
      wx.showModal({
        title: '收藏',
        content: '确定是否收藏？',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            post("/user/collect", { uid: that.data.uid, type: 1, id: that.data.id }).then(data => {
              console.log("-确定是否收藏？======" + data.data);
              that.setData({
                is_collect: 1
              })
              wx.showToast({
                title: data.msg,
                icon: 'succes',
                duration: 1000,
                mask: true
              })
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else if (that.data.is_collect == 1) {
      wx.showModal({
        title: '取消收藏',
        content: '是否取消收藏？',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            post("/user/uncollect", { uid: that.data.uid, type: 1, id: that.data.id }).then(data => {
              console.log("-确定是否取消收藏？======" + data.data);
              that.setData({
                is_collect: 0
              })
              wx.showToast({
                title: '已取消收藏',
                icon: 'succes',
                duration: 1000,
                mask: true
              })
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },
  juesescTab: function (e) {
    var that = this;
    var is_collect = e.currentTarget.dataset.collect;
    if (is_collect == 0) {
      wx.showModal({
        title: '角色收藏',
        content: '确定是否收藏该角色？',
        success: function (res) {
          if (res.confirm) {
            post("/user/collect", { uid: that.data.uid, type: 2, id: that.data.id }).then(data => {
              console.log("-确定是否收藏？======" + data.data);
              wx.showToast({
                title: data.msg,
                icon: 'succes',
                duration: 1000,
                mask: true
              })
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else if (is_collect == 1) {
      wx.showModal({
        title: '取消角色收藏',
        content: '是否取消收藏该角色？',
        success: function (res) {
          if (res.confirm) {
            post("/user/uncollect", { uid: that.data.uid, type: 2, id: that.data.id }).then(data => {
              console.log("-是否取消收藏该角色？======" + data.data);
              wx.showToast({
                title: '已取消收藏',
                icon: 'succes',
                duration: 1000,
                mask: true
              })
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },
  shenqingTab: function (e) {
    var that = this;
    var is_sign = e.currentTarget.dataset.sign;
    var id = e.currentTarget.dataset.id;
    if (is_sign == 0) {
      wx.showModal({
        title: '角色申请',
        content: '是否申请该角色？',
        success: function (res) {
          if (res.confirm) {
            post("/film/applyRole", { uid: that.data.uid, rid: id }).then(data => {
              console.log("-是否申请该角色？======" + data.data);
              // wx.showToast({
              //   title: data.msg,
              //   icon: 'succes',
              //   duration: 1000,
              //   mask: true
              // })
              wx.showModal({
                title: '提示',
                content: data.msg,
                success: function (res) {
                  if (res.confirm) {
                    console.log('用户点击确定')
                  } else if (res.cancel) {
                    console.log('用户点击取消')
                  }
                }
              })
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })

    } else if (is_sign == 1) {
      // wx.showToast({
      //   title: '已申请,请不要重复申请',
      //   icon: 'succes',
      //   duration: 1000,
      //   mask: true
      // })
      wx.showModal({
        title: '提示',
        content: '已申请,请不要重复申请',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },
})

